<%@ page language="java" %>
<%@ page errorPage="../error.jsp" %>
<%@ page import="org.hibernate.SessionFactory" %>
<%@ page import="org.unitime.timetable.model.dao._RootDAO" %>
<%@ page import="org.unitime.commons.web.Web" %>
<%@ page import="org.unitime.commons.hibernate.stats.StatsProvider" %>
<%@ taglib uri="/WEB-INF/tld/timetable.tld" prefix="tt" %>
<%
	if (!Web.isLoggedIn(session) || !Web.isAdmin(session))
            throw new Exception ("Access Denied.");
    boolean details = "true".equals(request.getParameter("details"));
	if (request.getParameter("enable")!=null) {
		new _RootDAO().getSession().getSessionFactory().getStatistics().setStatisticsEnabled("true".equals(request.getParameter("enable")));
	}
	boolean enabled = new _RootDAO().getSession().getSessionFactory().getStatistics().isStatisticsEnabled();
%>
<TABLE width="100%">
		<TR>
			<TD>
				<tt:section-header>
					<tt:section-title>
						<%=details?"Detailed Statistics":"Summary Statistics"%>
					</tt:section-title>
					<input type='button' onclick="document.location='hibernateStats.do?details=<%=details%>&enable=<%=!enabled%>';" value='<%=enabled?"Disable":"Enable"%> Statistics'>
					<input type='button' onclick="document.location='hibernateStats.do?details=<%=!details%>';" value='<%=details?"Hide Details":"Show Details"%>'>
				</tt:section-header>
			</TD>
		</TR>
		<TR>
			<TD>
				<%=StatsProvider.getStatsHtml(!details)%>
			</TD>
		</TR>
		<TR>
			<TD>
				<tt:section-title/>
			</TD>
		</TR>
		<TR>
			<TD align='right'>
				<input type='button' onclick="document.location='hibernateStats.do?details=<%=details%>&enable=<%=!enabled%>';" value='<%=enabled?"Disable":"Enable"%> Statistics'>
				<input type='button' onclick="document.location='hibernateStats.do?details=<%=!details%>';" value='<%=details?"Hide Details":"Show Details"%>'>
			</TD>
		</TR>
</TABLE>